//
//  APITestViewController.m
//  EnjoyArkUIXIOS
//
//  Created by Dordly on 2024/4/1.
//

#import "APITestViewController.h"
#import <libarkui_ios/BridgePlugin.h>
#import <libarkui_ios/StageApplication.h>
#import "BridgeClass.h"
#import "PublicAlertView.h"

@interface APITestViewController () <IMessageListener, IMethodResult>

@property (nonatomic, strong) UIView *mainView;
@property (nonatomic, strong) BridgeClass *plugin;
@property (nonatomic, strong) BridgeClass *binary_plugin;

@property (nonatomic, strong) StageViewController *stageVC;
@property (nonatomic, strong) PublicAlertView *publicAlertView;

@end

@implementation APITestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController setNavigationBarHidden:YES];
//    [self setNavigationBarWithCenterTitle:self.titleName];
//    [self createUI];
    ;
//    NSLog(@"languages--------%@", [NSLocale preferredLanguages]);
}

//- (void)createUI {
//    CGFloat topHeight = [self getStatusBarHeight] + [self getNavigationBarHeight];
//    self.mainView = [[UIView alloc] init];
//    self.mainView.frame = CGRectMake(0, topHeight, self.view.frame.size.width, self.view.frame.size.height - topHeight);
//    [self.view addSubview:self.mainView];
//    self.stageVC = [[StageViewController alloc] initWithInstanceName:self.instanceName];
//    self.stageVC.view.frame = CGRectMake(0, 0, self.mainView.frame.size.width, self.mainView.frame.size.height);
//    self.stageVC.view.backgroundColor = [UIColor whiteColor];
//    [self.mainView addSubview:self.stageVC.view];
//    [self addChildViewController:self.stageVC];
////    [self initBridgePlugin];
//}

//// 建立与ArkUI侧同名的平台桥接，即可用于消息传递
//- (void)initBridgePlugin {
//    BOOL isTaskOption = NO;
//    NSString *bridgePluginName = @"TestBridge";
//    BridgePluginManager *manager = [self.stageVC getBridgeManager];
//    BridgeType bridgeType = JSON_TYPE;
//    TaskOption *option = [[TaskOption alloc] initTaskOption:isTaskOption];
//    self.plugin = [[BridgeClass alloc] initBridgePlugin:bridgePluginName bridgeManager:manager bridgeType:bridgeType taskOption:option];
//    self.plugin.messageListener = self;
//    self.plugin.methodResult = self;
//    
//    self.binary_plugin = [[BridgeClass alloc] initBridgePlugin:@"Create_Binary_Bridge" bridgeManager:manager bridgeType:BINARY_TYPE];
//    self.binary_plugin.messageListener = self;
//    self.binary_plugin.methodResult = self;
//}
//
//
//#pragma mark - IMessageListener ArkUI侧发送的消息代理实现 （注意 BridgePlugin 对象 messageListener 属性添加监听者）
///**
//  *  Arkui测调用sendMessage 发送消息到IOS测，将会触发次方法的回调
//  *  @param data Arkui 传递过来的数据
//  *   return 返回值传递传递给Arkui测
//*/
//- (id)onMessage:(id)data {
//    NSString *bridgeNameStr = @"";
//    if ([data isKindOfClass:[NSString class]]) {
//        bridgeNameStr = data;
//    }
//    if ([bridgeNameStr containsString:@"testBridge_NativeToTs_callMethod"]) {
//        return @"testBridge_NativeToTs_callMethod success";
//    }
//    if ([bridgeNameStr containsString:@"Native-ArkUI_ParamMethod"]) {
//        MethodData *data = [[MethodData alloc] initMethodWithName:@"testCallBackOfJs" parameter:@[@"信息1"]];
//        [self.plugin callMethod:data];
//        return @"Native-ArkUI_ParamMethod success";
//    }
//    if ([bridgeNameStr containsString:@"Native-ArkUI_noParamMethod"]) {
//        MethodData *data = [[MethodData alloc] initMethodWithName:@"jsMethod" parameter:@[]];
//        [self.plugin callMethod:data];
//        return @"Native-ArkUI_noParamMethod success";
//    }
//    if ([bridgeNameStr containsString:@"testBridge_sendMessage"]) {
//        return @"testBridge_sendMessage success";
//    }
//    if ([bridgeNameStr containsString:@"estBridge_sendMessageCallBack"]) {
//        return @"estBridge_sendMessageCallBack success";
//    }
//    NSLog(@"Arkui 传递消息给iOS message: %@", data);
//    return @"哈哈哈，传入的是这个";
//}
//
///**
// * iOS 通过sendMessage 方法发送消息到Arkui, Arkui成功接到消息后回调此方法传递结果
// * @param data Arkui 返回的信息
//*/
//- (void)onMessageResponse:(id)data {
//    NSLog(@"onMessageResponse：ets返回原生信息:data：%@", data);
//}
//
//#pragma mark - IMethodResult 用于监听平台侧调用ArkUI侧注册的方法的执行情况
///**
//  *  ArkUI侧调用unRegisterMethod方法时将触发该接口，用于通知平台侧事件被注销了。
//  *  @param methodName ArkUI侧方法的名称
//  *  @param resultValue ResultValue 类 ，并将ArkUI侧方法的返回值传递给平台侧
//*/
//- (void)onSuccess:(NSString *)methodName resultValue:(id)resultValue {
//    NSLog(@"success：ets返回原生信息：%@ ==== %@", methodName, resultValue);
//    NSString *messageStr = [NSString stringWithFormat:@"%@回调成功TS->Native：%@", methodName, resultValue];
//    dispatch_async(dispatch_get_main_queue(), ^{
//        if (self.publicAlertView) {
//            [self.publicAlertView removeFromSuperview];
//        }
//        self.publicAlertView = [[PublicAlertView alloc] initWithFrame:self.view.frame mainTitle:messageStr];
//        [self.view addSubview:self.publicAlertView];
//        [self.publicAlertView showView];
//    });
//    [self.plugin sendMessage:resultValue];
//}
//
///**
//  *  ArkUI侧调用unRegisterMethod方法时将触发该接口，用于通知平台侧事件被注销了。
//  *  @param methodName ArkUI侧方法的名称
//*/
//- (void)onMethodCancel:(NSString *)methodName {
//    NSString *messageStr = [NSString stringWithFormat:@"%@ 取消成功", methodName];
//    [self.plugin sendMessage:messageStr];
//    dispatch_async(dispatch_get_main_queue(), ^{
//        if (self.publicAlertView) {
//            [self.publicAlertView removeFromSuperview];
//        }
//        self.publicAlertView = [[PublicAlertView alloc] initWithFrame:self.view.frame mainTitle:messageStr];
//        [self.view addSubview:self.publicAlertView];
//        [self.publicAlertView showView];
//    });
//    NSLog(@"Cancel：ets返回原生信息：%@", methodName);
//}
//
///**
//  *  平台侧调用ArkUI侧定义方法时，如果出错则触发该接口，并将出错信息返回平台侧。具体错误码查看ResultValue类中错误码或者接口文档
//  *  @param methodName ArkUI侧方法的名称
//  *  @param errorCode 错误码
//  *  @param errorMessage 错误信息
//*/
//- (void)onError:(NSString *)methodName errorCode:(ErrorCode)errorCode errorMessage:(NSString *)errorMessage {
//    NSLog(@"error：ets返回原生信息:methodName：%@ ==== errorMessage:%@ ====== errorCode:%d", methodName, errorMessage, errorCode);
//}


@end
